package utils;

import java.util.Collection;

import android.util.Log;

import com.google.common.base.CaseFormat;

public class StringUtil {

	/**
	 * Converts string of form "_myString"/"myString" to "my_string"
	 * @param iSource
	 * @return String
	 */
	public static final String underCamelToUnderScore(String iSource){

		String result=null;
		if(iSource!=null && !iSource.isEmpty()){
			if(iSource.charAt(0)=='_'){
				iSource=iSource.substring(1);
			}
			result = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, iSource);
		}
		return result;
	}

	/**
	 * Converts string of form "my_string" to "_myString"
	 * @param iSource
	 * @return String
	 */
	public static final String underScoreToUnderCamel(String iSource,Boolean isVariableName){
		String result=null;
		if(iSource!=null && !iSource.isEmpty()){
			result = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, iSource);
			if(isVariableName){
				result="_"+result;
			}
		}
		return result;
	}

	/**
	 * Prints the passed Collection contents one in a line.
	 * @param icollection
	 */
	public static final void printCollectionLines(Collection<?> icollection){
		if(icollection!=null && !icollection.isEmpty()){
			for(Object o:icollection){
				System.out.println(o.toString());
			}
		}
	}


	/**
	 * Prints the passed Collection contents one in a line.
	 * @param icollection
	 */
	public static final void androidLogCollectionLines(Collection<?> icollection,String iTag){
		if(icollection!=null && !icollection.isEmpty()){
			for(Object o:icollection){
				Log.i(iTag, o.toString());
			}
		}
	}

}
